Tutorial: Making applications with dynamic layout

In this tutorial you learn how to create user interfaces that respond to the changes of the device screen resolution. A user interface with a dynamic layout looks good and is easy to use regardless of the device and its screen resolution.

This video shows the result of the tutorial.

This tutorial assumes you understand the basics of working with Kanzi Studio. The best entry points for getting familiar with Kanzi Studio are:

Assets for the tutorial

The <KanziWorkspace>/Tutorials/Dynamic layout/Completed directory contains the completed project of this tutorial.

The starting point of this tutorial is the Dynamic layout.kzproj Kanzi Studio project file stored in the <KanziWorkspace>/Tutorials/Dynamic layout/Assets directory.

User interfaces with dynamic layout respond to changes in device screen orientation and resolution. Grid Layout nodes form the base of dynamic layouts. To make your Kanzi application layout dynamic, you have to place inside Grid Layout nodes all content for which you want that it responds to the changes in the screen resolution. Then you set up the Grid Layout nodes so that they position and distribute the content the way you want.

The project contains the two Grid Layout 2D nodes you need to complete this tutorial:

Make the layout of the user interface dynamic

In this section you make the layout of the user interface (Player and Controls Grid Layout 2D nodes) respond to the changes of the device screen orientation and resolution.

In this project the RootPage fills the entire device screen. Because the size of the RootPage node changes with the device resolution, use its height and width as a base for setting the dimensions of nodes in your user interface.

To make the layout of the user interface responsive:

  1. In Kanzi Studio open the project stored in the <KanziWorkspace>/Tutorials/Dynamic layout/Assets directory.
  2. (Optional) In the Preview click to enter the Analyze mode, right-click , and select Debug objects.
    This way you visualize the columns and rows of Grid Layout nodes.
  3. In the Project select the Player node, in the Properties add the Bindings property, and in the Binding Argument Editor set:
  4. In the Project select the Player node, in the Properties click + Add Binding, and in the Binding Argument Editor set:
  5. In the Project select the Controls node, in the Properties add the Bindings property, and in the Binding Argument Editor set:
  6. In the Project select the Controls node, in the Properties click + Add Binding, and in the Binding Argument Editor set:

Make the content in the user interface responsive

In this section you make the content of the Controls Grid Layout 2D node respond to the changes of the device screen orientation and resolution. That way the controls in the user interface change with changes of the screen resolution.

To make the content in the user interface responsive:

  1. In the Project select the Song list Image node, in the Properties add the Bindings property, and in the Binding Argument Editor set:
  2. Repeat the previous step for the Layout Width property of the Song list node, and use this binding expression:
    CLAMP(10, 60, {@../Node.Width} / 20)
    Click Save.
    This result of this binding is the same as for the binding in the previous step, but sets the Layout Width of the Song list node.
  3. Apply the same bindings you created in the Song list node to the other Image nodes in the Controls node.
    1. In the Project select the Song list node, in the Properties right-click the Bindings property, and select Copy.
    2. In the Project press Ctrl and click Back, Play, Forward, and More nodes.
    3. In the Project right-click the selected nodes and select Paste Property.
      In this way you can add and apply the copied Bindings property and its bindings to all selected nodes.
  4. In the Project select the Play Image node, in the Properties click the Layout Height binding, and in the Binding Argument Editor set Expression to
    CLAMP(50, 120, {@../../../Node.ActualHeight} / 5)

    Click Save.
    This binding sets the height of the Play Image node based on the height of the RootPage node. With this binding the size of the Play node changes differently from the other nodes in the Controls node.

  5. Repeat the previous step for the Layout Width property of the Play node, and use this binding expression:
    CLAMP(50, 120, {@../../../Node.ActualWidth} / 5)
    Click Save.
  6. In Kanzi Studio select File > Export > Export as KZB Player for Windows and open the .exe file of the application in the <ProjectName>/Application Player directory.
    When you adjust the size of the application window you simulate the changes in the resolution of the device screen. Notice how the size of the user interface changes according to the bindings you created in the project.

What's next?

In this tutorial you learned how to create a user interface the size of which responds to the changes of the device screen resolution. This project contains Text Block nodes the text of which stays the same regardless of the changes in the device screen resolution. You can use the approach you learned in this tutorial to make the size of the text in the Text Block nodes respond to the changes of the device screen resolution.

You can also:

See also

To learn more about how the Grid Layout nodes work, see Using the Grid Layout nodes.

To learn more about using bindings, see Using bindings and Bindings expressions reference.